<?php
namespace Admin\Controller;
use Think\Controller;
class AccountController extends CommonController {
	public function _initialize(){
		
		parent::check();
	}
	
    public function add(){
		
        $this->display();
    }
    //添加管理员数据到数据库
    public function insert(){
		$account	= I('post.account');
		$password	= I('post.password');
		
		$rules = array(
		 array('account','require','管理员必须！'), // 用户名必须
		 array('account','','帐号名称已经存在！',1,'unique',1), // 验证用户名是否已经存在
		 array('password','6,30','密码长度不正确',0,'length'), // 验证密码是否在指定长度范围
		 array('repassword','password','确认密码不一致',0,'confirm'), // 验证确认密码是否和密码一致  
		);

		$Account = M("Account"); // 实例化Account对象
		$res = $Account->validate($rules)->create();
		
		if( $res == false){
			$this->error($Account->getError());
		}
		else{
			$data = array(
				'account'	=> $account,
				'password'	=> md5($password),
				'addtime'	=> time()
			);
			
			
			$res = $Account->add($data);
			
			if( $res ==false){
				$this->error('添加失败');
			}
			$this->success('添加成功');
			
		}
	}
}
